public class Solution {
    public int Fibonacci(int n) {

        // 递归
        /*
        if (n < 3)
            return 1;
        
        return Fibonacci(n - 1) + Fibonacci(n - 2);
        */

        // 迭代相加
        /*
        if (n < 3)
            return 1;

        int ret = 0;
        int a = 1, b = 1;
        for (int i = 2; i < n; i++) {
            ret = a + b;
            int temp = b;
            b = ret;
            a = temp;
        }

        return ret;
        */

        // 动态规划
        if (n < 3)
            return 1;

        int[] dp = new int[n];
        dp[0] = dp[1] = 1;
        for (int i = 2; i < n; i++) {
            dp[i] = dp[i - 2] + dp[i - 1];
        }
        return dp[n - 1];
    }
}
